<?php
/**
 * Lớp model thống kê cho hệ thống
 * [[
 * table: counter
 * database: default
 * read_only: false
 * primaryKey: id
 * ]]
 */
class Models_Counter extends XPHP_Model
{
	public $id;
	
	public $visits;
	
	public function addVisits()
	{
		++$this->visits;
		$this->update();
	}
	
	function getOnlineUsers()
	{ 
		$directory_handle = opendir(session_save_path());
		$count = 0; 
		while (false !== ($file = readdir($directory_handle)))
		{ 
			if($file != '.' && $file != '..')
			{ 
				// Comment the 'if(...){' and '}' lines if you get a significant amount of traffic 
				//if(time()- fileatime(session_save_path() . '\\' . $file) < MAX_IDLE_TIME * 60)
				if(ereg("^sess", $file))
				$count++; 
			}
		}
		closedir($directory_handle); 
		return $count; 
	} 
}